home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / printer / println.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  3.0 KB  |  111 lines

  1. ;void  println(strg);
  2. ;  char  *strg;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _error_code:byte
  6.     EXTRN  _time_out:byte
  7.  
  8. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  9.     ASSUME  CS:_TEXT
  10.     PUBLIC  _println
  11. _println proc near
  12.     jmp  short start    ;jmp over local data
  13. delay    dw   ?            ;
  14. target  dw   ?            ;
  15. start:    push bp            ;
  16.     mov  bp,sp        ;set stack frame
  17.     push si            ;
  18.     cmp  _memory_model,0    ;near or far?
  19.     jle  begin        ;jump if near
  20.     inc  bp            ;else add 2 to BP
  21.     inc  bp            ;
  22. begin:    push ds            ;save DS
  23.     mov  ah,1        ;BIOS func to init prtr
  24.     mov  dx,0        ;choose LPT1
  25.     int  17h        ;initialize the prtr port
  26.     sub  ax,ax        ;AX = 0
  27.     mov  es,ax        ;ES = 0
  28.     mov  dx,es:[408H]    ;get LPT1 base address
  29.     sub  bx,bx        ;0 = no error
  30.     mov  al,_time_out    ;get _time_out seconds
  31.     cmp  _memory_model,2    ;data near or far?
  32.     jb   L0            ;jump if near
  33.     lds  si,dword ptr[bp+4] ;DS:SI pts to Strg
  34.     jmp  short L00        ;
  35. L0:    mov  si,[bp+4]        ;near case
  36. L00:    or   al,al        ;don't allow zero seconds
  37.     jnz  L1            ;
  38.     mov  al,3        ;default to 3 seconds
  39. L1:    mov  cl,18        ;18 ticks per second
  40.     mul  cl            ;
  41.     mov  cs:delay,ax    ;save count
  42.     cmp  byte ptr[si],0    ;test for null string
  43.     je   L5            ;
  44. L2:    mov  al,[si]        ;mov character to AL
  45.     cmp  al,0        ;end of string?
  46.     je   L5            ;
  47.     inc  si            ;forward pointer for next time
  48. L3:    out  dx,al        ;send to output data register
  49.     inc  dx            ;forward to status register
  50.     push cx            ;save string counter
  51.     push bx            ;
  52.     call GetBiosCount    ;get timer reading
  53.     mov  bx,cx        ;make copy
  54.     add  cx,cs:delay    ;add delay count
  55.     cmp  bx,cx        ;if timer doesn't turn over...
  56.     jb   L4            ;go ahead
  57.     mov  cx,cs:delay    ;otherwise, extend delay
  58. L4:    mov  cs:target,cx    ;save target count on stack
  59.     pop bx            ;
  60. Wait:    in   al,dx        ;get status value
  61.     test al,8        ;test for printer error
  62.     jz   Error        ;
  63.     test al,80h        ;test for Printer Ready
  64.     jnz  Ready        ;jump if ready
  65. Error:    call GetBiosCount    ;
  66.     cmp  cx,cs:target    ;compare to target
  67.     jb   Wait        ;    
  68.     mov  bl,1        ;1 = error
  69.     pop  cx            ;restore string counter
  70.     jmp  short L7        ;go quit routine
  71. Ready:    pop  cx            ;restore string counter
  72.     inc  dx            ; output control register
  73.     mov  al,13        ;bits for strobe signal
  74.     out  dx,al        ;send the signal
  75.     dec  al            ;change to strobe OFF
  76.     out  dx,al        ;send the signal
  77.     dec  dx            ;point back to
  78.     dec  dx            ;  base address
  79.     jmp  short L2        ;loop
  80. L5:    inc  cx            ;will reenter loop
  81.     cmp  bh,2        ;BH = 0 first time around
  82.     je   L7            ;when 2, quit routine
  83.     inc  bh            ;inc BH before looping
  84.     cmp  bh,2        ;second time?
  85.     jne  L6            ;jump ahead if not
  86.     mov  al,13        ;ready carriage return
  87.     jmp  short L3        ;go print it
  88. L6:    mov  al,10        ;ready line feed
  89.     jmp  short L3        ;go print it
  90. L7:    pop  ds            ;restore DS
  91.     mov  _error_code,bl    ;set _error_code
  92.     pop  si            ;
  93.     pop  bp            ;
  94.     cmp  _memory_model,0    ;quit
  95.     jle  quit        ;
  96.     db   0CBh        ;RET far
  97. quit:    ret            ;RET near
  98. GetBIOSCount PROC
  99.     push dx            ;return value in CX:DX
  100.     push ax            ;
  101.     sub  ah,ah        ;function number
  102.     int  1ah        ;get timer count
  103.     mov  cx,dx        ;low word in CX
  104.     pop  ax            ;
  105.     pop  dx
  106.     ret
  107. GetBIOSCount endp
  108. _println endp
  109. _TEXT    ENDS
  110.     END
  111.